package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ExtHelper;
import com.ruoyi.common.utils.SpellUtils;
import com.ruoyi.common.utils.uuid.IdGeneratorSnowflake;
import com.ruoyi.system.domain.TrainingBaseMentor;
import com.ruoyi.system.domain.TrainingBaseMentorAll;
import com.ruoyi.system.mapper.TrainingBaseMentorMapper;
import com.ruoyi.system.service.ITrainingBaseMentorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 培训导师信息Service业务层处理
 *
 * @author dp
 * @date 2023-11-27
 */
@Service
public class TrainingBaseMentorServiceImpl implements ITrainingBaseMentorService {
    @Autowired
    private TrainingBaseMentorMapper trainingBaseMentorMapper;
    @Autowired
    IdGeneratorSnowflake idGeneratorSnowflake;

    /**
     * 查询培训导师信息
     *
     * @param mentorId 培训导师信息主键
     * @return 培训导师信息
     */
    @Override
    public TrainingBaseMentorAll selectTrainingBaseMentorByMentorId(Long mentorId) {
        return trainingBaseMentorMapper.selectTrainingBaseMentorByMentorId(mentorId);
    }

    /**
     * 查询培训导师信息列表
     *
     * @param trainingBaseMentor 培训导师信息
     * @return 培训导师信息
     */
    @Override
    public List<TrainingBaseMentorAll> selectTrainingBaseMentorList(TrainingBaseMentor trainingBaseMentor) {
        return trainingBaseMentorMapper.selectTrainingBaseMentorList(trainingBaseMentor);
    }

    /**
     * 新增培训导师信息
     *
     * @param trainingBaseMentor 培训导师信息
     * @return 结果
     */
    @Override
    public int insertTrainingBaseMentor(TrainingBaseMentor trainingBaseMentor) {
        trainingBaseMentor.setCreateTime(DateUtils.getNowDate());
        return trainingBaseMentorMapper.insertTrainingBaseMentor(trainingBaseMentor);
    }

    /**
     * 修改培训导师信息
     *
     * @param trainingBaseMentor 培训导师信息
     * @return 结果
     */
    @Override
    public int updateTrainingBaseMentor(TrainingBaseMentor trainingBaseMentor) {
        return trainingBaseMentorMapper.updateTrainingBaseMentor(trainingBaseMentor);
    }

    /**
     * 批量删除培训导师信息
     *
     * @param mentorIds 需要删除的培训导师信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingBaseMentorByMentorIds(Long[] mentorIds) {
        return trainingBaseMentorMapper.deleteTrainingBaseMentorByMentorIds(mentorIds);
    }

    /**
     * 删除培训导师信息信息
     *
     * @param mentorId 培训导师信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingBaseMentorByMentorId(Long mentorId) {
        return trainingBaseMentorMapper.deleteTrainingBaseMentorByMentorId(mentorId);
    }

    /**
     * 实体数据补全
     *
     * @param trainingBaseMentor 实体
     * @param userId             用户id
     * @param crateType          创建类型 1：新增 2：修改
     */
    @Override
    public void completeData(TrainingBaseMentor trainingBaseMentor, Long userId, Integer crateType) {
        //主键
        if (trainingBaseMentor.getMentorId() == null || "".equals(trainingBaseMentor.getMentorId())) {
            trainingBaseMentor.setMentorId(ExtHelper.toString(idGeneratorSnowflake.nextId()));
        }
        //编码
        if (trainingBaseMentor.getMentorCode() == null || "".equals(trainingBaseMentor.getMentorCode())) {
            trainingBaseMentor.setMentorCode(SpellUtils.convertSpell(trainingBaseMentor.getMentorName(), false));
        }
        //是否有效
        if (trainingBaseMentor.getIsValid() == null) {
            trainingBaseMentor.setIsValid(1L);
        }
        //创建人、创建时间
        if (crateType == 1) {
            if (trainingBaseMentor.getCreateBy() == null) {
                trainingBaseMentor.setCreateBy(userId.toString());
            }
            if (trainingBaseMentor.getCreateTime() == null) {
                trainingBaseMentor.setCreateTime(DateUtils.getNowDate());
            }
        }
        //修改人
        if (trainingBaseMentor.getModifyBy() == null) {
            trainingBaseMentor.setModifyBy(userId);
        }
        //修改时间
        if (trainingBaseMentor.getModifyTime() == null) {
            trainingBaseMentor.setModifyTime(DateUtils.getNowDate());
        }
    }
}
